import { defineStore } from 'pinia'
import { ref } from 'vue'
import { MemberAddressItem } from '@/types/address'

export const userAddressesStore = defineStore('address', () => {
  // 定义选中的收货地址
  const selectedAddress = ref({} as MemberAddressItem)
  // 定义保存选中收货地址的方法
  const changeSelectedAddress = (addresInfo: MemberAddressItem) => selectedAddress.value = addresInfo
  return {
    selectedAddress,
    changeSelectedAddress
  }
},
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          return uni.setStorageSync(key, value)
        }
      }
    }
  }
)